<html>
<head>

		<?php
        INCLUDE 'header.php';
		
		if(isset($_POST["filtro"]))
		{
		$filtro = $_POST["filtro"];
		$complemento = " where nome ILIKE '%$filtro%'";
		}		


		//$sql = "select * from vacinacao".$complemento;
		//monto a consulta
		//vc.id, vc.data, v.nome, a.nome, f.nome, vc.obs
		$sql = "select *, v.nome as nomevacina, a.nome as nomeanimal, f.nome as nomefazenda from vacinacao vc
		INNER JOIN vacina v ON v.id = vc.idvacina
		INNER JOIN animal a ON a.id = vc.idanimal
		INNER JOIN fazenda f ON f.id = vc.idfazenda".$complemento;
		

		
	 //executo no banco, retornando os registros da tabela
		$lista = pg_query($sql);
	 
	 ?>
       <meta http-equiv="Content-Type" content="text/html" charset="UTF-8">
	
		<title>Sistema de controle de fazendas</title>
		  </head>
		  <body>
		<div class="pull-right"> 
		<div class="btn" title="nova vacinacao"><i class="icon-edit"></i><a></a></div>
		<div class="btn" title="sair"><i class="icon-share-alt"></i><a></a></div>
		</div>
		<legend><i class="icon-search"></i>Pesquisar vacinação</legend>
	  
		<form class="form-search" action="listarVacinacao.php" method="post">
	
		<input class="input-medium search-query" placeholder="faça sua busca" type="text" name="filtro"></input>
		<button class="btn btn-warning" type="submit" value="pesquisar">buscar</button>
		</form>
	
		
	<table class="table table-hover">
    <caption></caption>
    <thead>
	 <tbody>
    <tr class="info">
    <th>Id</th>
    <th>Data</th>
	<th>Animal</th>
	<th>Fazenda</th>
	<th>Vacina</th>
	<th>obs</th>
	
    </tr>
    </thead>
  <?php
   while($vacinacao = pg_fetch_assoc($lista))
   {
   
   ?>
   
    <tr>
    <td><?php echo $vacinacao ["id"]?></td>
    <td><?php echo $vacinacao ["data"]?></td>
	<td><?php echo $vacinacao ["nomeanimal"]?></td>
	<td><?php echo $vacinacao ["nomefazenda"]?></td>
	<td><?php echo $vacinacao ["nomevacina"]?></td>
	<td><?php echo $vacinacao ["obs"]?></td>
	   
	<td><a title="excluir" href="vacinacao-excluir-ok.php?id=<?php echo $vacinacao["id"]?>"><i class="icon-trash"></i></a>
	<a title="alterar" href="cadastroVacinacao.php?id=<?php echo $vacinacao["id"]?>"><i class="icon-pencil"></i></a></td> </tr>
  <?php 
   }
    ?>
  
    </tbody>
    </table>
    </table>
	</body>
</html>
<!--youtube.com/programatcheif-->